package com.etime.shycourse.controller.wx.rss;

import com.etime.shy.common.BaseMessage;
import com.etime.shycourse.orde.pojo.Orderdetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信订阅消息controller
 */
@Api(tags = "微信订阅消息前端调用接口")
@RestController
@RequestMapping("/wx/rss")
public class WXRSSController {
    @Autowired
    private WXRSSService wxrssService;

    @ApiOperation("向客户推送微信订阅消息")
    @PostMapping("/push")
    public BaseMessage pushMessage(@RequestBody WXRSSData wxrssData){
        BaseMessage msg = new BaseMessage();
//        WXRSSData wxrssData = new WXRSSData();
//        wxrssData.setTouser("ok__U4nRYYT0Rm3MPlAJ2OuKfDEw");
//        wxrssData.setPage("pages/member/service/mycourse");
//        wxrssData.setTemplate_id("JLhOkbE52OOA_vX6TWAoqnG7GDCl4ls_Wu4F6SLp-Pk");
//        Map<String, TemplateData> params = new HashMap<>();
//        params.put("thing1",new TemplateData("学习包"));
//        //List<Orderdetail> orderdetailList = orderDetails.getOrderdetailList();
//        params.put("character_string2",new TemplateData("1"));
//        params.put("thing3",new TemplateData("请到小程序我的课程中查看"));
//
//        params.put("thing5",new TemplateData("学习大礼包"));
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String time = df.format(new Date());
//        params.put("time8",new TemplateData(time));
//        wxrssData.setData(params);
        String rtn = wxrssService.pushmessage(wxrssData);
        msg.setMsg(rtn);
        return msg;
    }
}
